package com.alibaba.wallstreet.uitls;

import java.util.Date;

public class Tester {

    private static final String PASSPHRASE = "862317";

    private static final String DE_INPUT = "D:/work/海外汇丰银行业务/key_test/de/HVP-PP.pgp";
    private static final String DE_OUTPUT = "D:/work/海外汇丰银行业务/key_test/jieMi/HVP-PP1.xml";
    private static final String DE_KEY_FILE = "D:/work/海外汇丰银行业务/key/自己的公钥和私钥/secring.skr";

    private static final String E_INPUT = "D:/work/海外汇丰银行业务/key_test/en/HVP-PP.xml";
    private static final String E_OUTPUT = "D:/work/海外汇丰银行业务/key_test/de/HVP-PP.pgp";
    private static final String E_KEY_FILE = "D:/work/海外汇丰银行业务/key/自己的公钥和私钥/pubring.pkr";
    
    
    
    
    
    private static final String HSBC_PASSPHRASE = "838690";
    private static final String HSBC_DE_KEY_FILE = "D:/work/海外汇丰银行业务/key/汇丰的公钥和私钥/HSBCprivate.skr";
    //这是模拟的hsbc的公钥
    private static final String HSBC_E_KEY_FILE  = "D:/work/海外汇丰银行业务/key/汇丰的公钥和私钥/HSBCpublic.pkr";
    //HSBC的UAT公钥
//    private static final String HSBC_E_KEY_FILE  = "D:/work/海外汇丰银行业务/key/汇丰UAT公钥/HKHBAPftvu0232.asc";


    public static void testDecrypt() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName(DE_INPUT);
        p.setOutputFileName(DE_OUTPUT);
        p.setPassphrase(PASSPHRASE);
        p.setSecretKeyFileName(DE_KEY_FILE);
        System.out.println(p.decrypt());
    }

    public static void testEncrypt() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName(E_INPUT);
        p.setOutputFileName(E_OUTPUT);
        p.setPassphrase(PASSPHRASE);
        p.setPublicKeyFileName(E_KEY_FILE);
        System.out.println(p.encrypt());
    }
    
    /**
     * 用自己的私钥签名（私钥解密密码是862317）
     * 用汇丰的公钥加密
     * @throws Exception
     */
    public static void testSignEncrypt() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName(E_INPUT);
        p.setOutputFileName(E_OUTPUT);
        p.setPassphrase(PASSPHRASE);
        p.setPublicKeyFileName(HSBC_E_KEY_FILE);
        p.setSecretKeyFileName(DE_KEY_FILE);
        System.out.println(p.signEncrypt());
    }
    
    
    /**
     * 用自己的私钥签名（私钥解密密码是862317）
     * 用汇丰的公钥加密
     * @throws Exception
     */
    public static void testSignEncryptHSBC() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("D:/work/海外汇丰银行业务/key_test/en/ACKSTD1.CJ071.063017352226.xml");
        p.setOutputFileName("D:/work/海外汇丰银行业务/key_test/de/caodande/ACKSTD1.CJ071.063017352226.GPG");
        p.setPassphrase("12345678");
        p.setPublicKeyFileName("D:/work/海外汇丰银行业务/key/平时测试的key/alibaba_public.pkr");
        p.setSecretKeyFileName("D:/work/海外汇丰银行业务/key/平时测试的key/hsbc_private.skr");
        System.out.println(p.signEncrypt());
    }
    
    
    /**
     * 用自己的私钥签名（私钥解密密码是862317）
     * 用汇丰的公钥加密
     * @throws Exception
     */
    public static void testSignEncryptHSBCUAT() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("D:/work/海外汇丰银行业务/key_test/en/ACKSTD1.CJ071.063017352226.xml");
        p.setOutputFileName("D:/work/海外汇丰银行业务/key_test/de/caodande/ACKSTD1.CJ071.063017352226.GPG");
        p.setPassphrase("alibaba_uat2015");
        p.setSecretKeyFileName("D:\\work\\海外汇丰银行业务\\key\\汇丰UAT公钥\\uat\\alibaba_private_uat.gpg");
        p.setPublicKeyFileName("D:\\alibaba\\wallstreet\\deploy\\conf\\keystore\\hsbc_public_uat.asc");
        System.out.println(p.signEncrypt());
    }
    
    
    /**
     * 用汇丰的私钥解密,用自己的公钥验证签名
     * @throws Exception
     */
    public static void testDecryptVerifyHSBC() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("D:/work/海外汇丰银行业务/key_test/de/caodande/ACKSTD1.CJ071.063017352226.GPG");
        p.setOutputFileName("D:/work/海外汇丰银行业务/key_test/jieMi/ACKSTD1.CJ071.063017352226.xml");
        p.setPassphrase("12345678");
        p.setSecretKeyFileName("D:/work/海外汇丰银行业务/key/平时测试的key/alibaba_private.skr");
        p.setPublicKeyFileName("D:/work/海外汇丰银行业务/key/平时测试的key/hsbc_public.pkr");
        System.out.println(p.decryptVerify());
    }
    
    /**
     * 用汇丰的私钥解密
     * @throws Exception
     */
    public static void testDecryptHsbc() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName(DE_INPUT);
        p.setOutputFileName(DE_OUTPUT);
        p.setPassphrase(HSBC_PASSPHRASE);
        p.setSecretKeyFileName(HSBC_DE_KEY_FILE);
        System.out.println(p.decrypt());
    }
    
    /**
     * 用汇丰的私钥解密,用自己的公钥验证签名
     * @throws Exception
     */
    public static void testDecryptVerifyHsbc() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName(DE_INPUT);
        p.setOutputFileName(DE_OUTPUT);
        p.setPassphrase(HSBC_PASSPHRASE);
        p.setSecretKeyFileName(HSBC_DE_KEY_FILE);
        p.setPublicKeyFileName(E_KEY_FILE);
        System.out.println(p.decryptVerify());
    }
    
    /**
     * 用汇丰的私钥解密,用自己的公钥验证签名
     * @throws Exception
     */
    public static void testDecryptVerifyUAT() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("C:\\Users\\laijia.dlj\\Desktop\\前置机日志\\hsbc_pgp\\ACKSTD1.CJ071.081911213505.PGP");
        p.setOutputFileName("C:\\Users\\laijia.dlj\\Desktop\\前置机日志\\hsbc_pgp\\jiemi\\ACKSTD1.CJ071.081911213505.xml");
        p.setPassphrase("alibaba0510");
        p.setSecretKeyFileName("D:\\work\\海外汇丰银行业务\\alibaba_key\\alibaba_private_uat.pgp");
        p.setPublicKeyFileName("D:\\alibaba\\wallstreet\\deploy\\conf\\keystore\\hsbc_public_uat.asc");
//        System.out.println(p.decryptVerify());
        System.out.println(p.decryptVerifyStreamKey());
//        System.out.println(p.decryptVerify());
    }
    
    /**
     * 用汇丰的私钥解密,用自己的公钥验证签名
     * @throws Exception
     */
    public static void testDecryptVerifyUAT2() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("C:\\Users\\laijia.dlj\\Desktop\\前置机日志\\hsbc_pgp\\uat\\ACKSTD1.CJ071.081919092907.PGP");
        p.setOutputFileName("C:\\Users\\laijia.dlj\\Desktop\\前置机日志\\hsbc_pgp\\jiemi\\ACKSTD1.CJ071.081919092907.xml");
//        p.setPassphrase("alibaba0510");
//        p.setSecretKeyFileName("D:\\work\\海外汇丰银行业务\\alibaba_key\\alibaba_private_uat.pgp");
        p.setPassphrase("alibaba_uat2015");
        p.setSecretKeyFileName("D:\\work\\海外汇丰银行业务\\key\\汇丰UAT公钥\\uat\\alibaba_private_uat.gpg");
        p.setPublicKeyFileName("D:\\alibaba\\wallstreet\\deploy\\conf\\keystore\\hsbc_public_uat.asc");
//        System.out.println(p.decryptVerify());
        System.out.println(p.decryptVerifyStreamKey());
//        System.out.println(p.decryptVerify());
    }
    
    /**
     * 用汇丰的私钥解密
     * @throws Exception
     */
    public static void testDecryptUAT() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("C:\\Users\\laijia.dlj\\Desktop\\前置机日志\\hsbc_pgp\\ACKSTD1.CJ071.081911213505.PGP");
        p.setOutputFileName("C:\\Users\\laijia.dlj\\Desktop\\前置机日志\\hsbc_pgp\\jiemi\\ACKSTD1.CJ071.081911213505.xml");
        p.setPassphrase("alibaba0510");
        p.setSecretKeyFileName("D:\\work\\海外汇丰银行业务\\alibaba_key\\alibaba_private_uat.pgp");
        p.setPublicKeyFileName("D:\\alibaba\\wallstreet\\deploy\\conf\\keystore\\hsbc_public_uat.asc");
        System.out.println(p.decrypt());
    }
    
    /**
     * 用汇丰的私钥解密,用自己的公钥验证签名
     * @throws Exception
     */
    public static void testDecryptVerifyMyTest() throws Exception {
        PGPFileProcessor p = new PGPFileProcessor();
        p.setInputFileName("D:\\alibaba\\wallstreet\\biz\\core\\src\\test\\resources\\req_encrypt\\123456_20150814220750.PGP");
        p.setOutputFileName(DE_OUTPUT);
        p.setPassphrase(HSBC_PASSPHRASE);
        p.setSecretKeyFileName(HSBC_DE_KEY_FILE);
        p.setPublicKeyFileName(E_KEY_FILE);
        System.out.println(p.decryptVerify());
    }
    
   /** 
     // 只测试加密和解密，ok
    public static void main(String[] args) {
        try {
            testEncrypt();
            testDecrypt();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    **/
    
 
//    public static void main(String[] args) {
//        try {
////            testSignEncryptHSBC();
//            /**
//            long time1 = System.currentTimeMillis();
//            System.out.println(new Date().toString());
//            testSignEncrypt();
//            long time2 = System.currentTimeMillis();
//            System.out.println(time2 - time1);
//            System.out.println(new Date().toString());
//            **/
//            testDecryptVerifyHsbc();
////            testSignEncryptHSBC();
////            testSignEncryptHSBCUAT();
//            
//            //已经用了今天最新的uat key 测试了
////            testDecryptVerifyUAT2();
////            testDecryptUAT();
////            D:\alibaba\wallstreet\biz\core\src\test\resources\req_encrypt\123456_20150814220750.PGP
////            testDecryptVerifyHsbc();
////            testDecryptVerifyMyTest();
////            testDecryptVerifyHSBC();
//        } catch (Exception e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//    }
 
}